class TempUtils {

  /*
  * tempList 体温
  * defaultSkinTemperature 基准值 注：我们这边定义的是27
  */
  static List<double> getNewTempList(List<double> tempList, double defaultSkinTemperature) {
    double minTemp=25.0;
    double maxTemp=37.5;
    double skinTemperature = defaultSkinTemperature; // 体温基准值
    // 找基准值
    for (double tempValue in tempList) {
      if (tempValue > minTemp && tempValue < maxTemp) {
        skinTemperature = tempValue;
        break;
      }
    }

    double tempAllValue = 0;
    for (int i = 0; i < tempList.length; i++) {
      double tempByBase = countTempByBase(i, tempList[i], skinTemperature);
      tempList[i] = tempByBase;
      tempAllValue += tempByBase;
    }

    double tempAvg = tempAllValue / tempList.length;

    for (int i = 0; i < tempList.length; i++) {
      double tempValue = tempList[i];
      if (tempValue > 0) {
        tempList[i] = tempValue - tempAvg;
      }
    }

    return tempList;
  }

  static double countTempByBase(int index, double tempValue, double baseValue) {
    if (tempValue > baseValue - 2.4 && tempValue < baseValue + 2.4) {
      return baseValue + ((tempValue - baseValue) / 8) + 0.5;
    } else if (tempValue >= baseValue + 2.4 && tempValue < baseValue + 4.8) {
      return baseValue + 0.15 + ((tempValue - baseValue) / 16) + 0.5;
    } else if (tempValue >= baseValue + 4.8) {
      if (index > 0) {
        if (tempValue == 0) {
          return baseValue + 0.95;
        } else {
          return tempValue;
        }
      } else {
        return baseValue + 0.95;
      }
    } else if (tempValue <= baseValue - 2.4 && tempValue > baseValue - 4.8) {
      return baseValue - 0.15 + ((tempValue - baseValue) / 16);
    } else if (tempValue <= baseValue - 4.8) {
      if (index > 0) {
        if (tempValue == 0) {
          return baseValue + 0.05;
        } else {
          return tempValue;
        }
      } else {
        return baseValue + 0.05;
      }
    } else {
      return baseValue;
    }
  }

}